using System.Collections.Generic;
using UnityEngine;

public class HumanPlayerLookInitialiser : LookInitialiserBase
{
	public RuntimeAnimatorController animatorController;

	public GameObject playerModelPrefab;

	public bool skipShaderInitialization;

	public CustomisationConfig.ShadingType shadingType = CustomisationConfig.ShadingType.Normal;

	private TableTennisHumanPlayer _humanPlayerController;

	private TableTennisPlayerBase _tableTennisPlayer;

	private PersonaModel _model;

	private Persona myPersona;

	private TableTennisHumanPlayer humanPlayerController
	{
		get
		{
			if (_humanPlayerController == null)
			{
				_humanPlayerController = GetComponent<TableTennisHumanPlayer>();
			}
			return _humanPlayerController;
		}
	}

	private TableTennisPlayerBase tableTennisPlayer
	{
		get
		{
			if (_tableTennisPlayer == null)
			{
				_tableTennisPlayer = GetComponent<TableTennisPlayerBase>();
			}
			return _tableTennisPlayer;
		}
	}

	private PersonaModel model
	{
		get
		{
			if (_model == null)
			{
				_model = GetComponent<PersonaModel>();
			}
			return _model;
		}
	}

	private void CreatePlayerModel()
	{
		GameObject gameObject = Object.Instantiate(playerModelPrefab);
		gameObject.transform.parent = base.transform;
		gameObject.transform.localPosition = Vector3.zero;
		gameObject.transform.localRotation = Quaternion.identity;
		gameObject.GetComponent<Animator>().runtimeAnimatorController = animatorController;
		tableTennisPlayer.serveHand = gameObject.transform.Search("HAND LEFT");
		Transform transform = gameObject.transform.Search("SHOES002");
		transform.GetComponent<SkinnedMeshRenderer>().updateWhenOffscreen = true;
	}

	private void OnEnable()
	{
		CreatePlayerModel();
		if (!skipShaderInitialization)
		{
			ApplyPlayerModel(shadingType);
		}
		else if (humanPlayerController != null)
		{
			humanPlayerController.updateBallPos = new List<Transform>();
		}
	}

	public void ApplyPlayerModel(CustomisationConfig.ShadingType shadingType)
	{
		myPersona = new Persona(GGPlayerSettings.instance);
		MatchParameters.MatchParams initParameters = MatchParameters.InitParameters;
		if (initParameters.shoeOverride != null && initParameters.shoeOverride.shouldUseOverride)
		{
			CustomisationConfig.LookSet lookSetForType = CustomisationConfig.instance.GetLookSetForType(CustomisationConfig.LookSetType.Shoes);
			CustomisationConfig.Look lookByName = lookSetForType.GetLookByName(initParameters.shoeOverride.storeItem.customisationLookName, myPersona.gender);
			myPersona.ChangeLook(lookByName);
		}
		if (initParameters.racketOverride != null && initParameters.racketOverride.shouldUseOverride)
		{
			CustomisationConfig.LookSet lookSetForType2 = CustomisationConfig.instance.GetLookSetForType(CustomisationConfig.LookSetType.Racket);
			CustomisationConfig.Look lookByName2 = lookSetForType2.GetLookByName(initParameters.racketOverride.storeItem.customisationLookName, Persona.Gender.Male);
			myPersona.ChangeLook(lookByName2);
		}
		CustomisationConfig.instance.ApplyLooksForPersona(model, myPersona, CustomisationConfig.MatchShaderUseType(shadingType, CustomisationConfig.PlayerType.Human));
		List<Transform> partsToUpdateForTransparency = model.GetPartsToUpdateForTransparency();
		if (humanPlayerController != null)
		{
			humanPlayerController.updateBallPos = model.GetPartsToUpdateForTransparency();
		}
	}
}
